import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(name = "QueryBookServlet", value = "/QueryBookServlet")
public class QueryBookServlet extends HttpServlet {

    private BookDao bdao = new BookDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");


        String name = request.getParameter("name");
        String press = request.getParameter("press");
        String data = request.getParameter("pressdata");

        Gson gson = new Gson();
        String json = gson.toJson(bdao.query(name,press,data));

        response.getWriter().println(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
